<template>
  <!-- 传入内容 插槽内容 会循环多次 有多少节点 就循环多少次 -->
  <!-- 作用域插槽 slot-scope="obj" 接收传递给插槽的数据   data 每个节点的数据对象-->
  <el-row class="boxrow">
    <el-col :span="20" >
      <!-- 左侧内容 -->
      <i class="el-icon-s-home myicon"></i>
       <span class="fw">{{ item.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row class="myrow" type="flex" justify="end">
        <el-col>{{ item.manager }}</el-col>
        <el-col>
          <!-- 放置下拉菜单 -->
          <el-dropdown @command="operateDepts">
            <!-- 内容 -->
            <span class="el-dropdown-link">操作
              <i class="el-icon-arrow-down  el-icon--right" />
            </span>
            <!-- 具名插槽 -->
            <el-dropdown-menu slot="dropdown">
              <!-- 下拉选项 -->
              <el-dropdown-item command="add" >添加子部门</el-dropdown-item>
              <el-dropdown-item command="edit" v-if="!item.isTop">编辑部门</el-dropdown-item>
              <el-dropdown-item command="del" v-if="!item.isTop">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>

      <!-- 右侧内容 -->
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments'

export default {
props:['item'],
methods:{
  operateDepts(type){
    if (type==='add') {
      //添加子部门
      this.$emit('addDepts',this.item) 
    }else if(type==='edit'){
      //编辑子部门
      this.$emit('editDepts',this.item)
      console.log('编辑');
    }else{
      //删除
      this.$confirm('确定删除该部门吗').then(()=>{
        //如果点击确定就会进入then
        return delDepartments(this.item.id) //返回promise对象
      }).then(()=>{
        //删除成功
        this.$emit('delDepts')
        this.$message.success('删除部门成功')
      })

    }
  }
}
}
</script>

<style lang="scss" scoped>
    .boxrow{
        width: 100%;
        font-size: 14px;
        .myicon{
            margin-right: 6px;
        }
        .fw{
            font-weight: 700;
        }
        .myrow{
            display:flex;
            ::v-deep .el-col{
                text-align: right;
            }
        }


    }
</style>

